package com.zxx.mvpPractice.ui.fragment;

import android.app.ProgressDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.google.common.base.Preconditions;
import com.zxx.mvpPractice.R;
import com.zxx.mvpPractice.base.BaseFragment;
import com.zxx.mvpPractice.presenter.LoginFragmentPresenter;
import com.zxx.mvpPractice.presenter.contract.LoginFragmentContract;
import com.zxx.mvpPractice.ui.activitys.LoginActivity;
import com.zxx.mvpPractice.utils.EventUtil;
import com.zxx.mvpPractice.utils.KL;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 手机发送验证码登录
 * Created by Administrator on 2016/12/30.
 */
public class LoginRegisterFragment extends BaseFragment<LoginFragmentContract.Presenter> implements LoginFragmentContract.View {

    @BindView(R.id.edt_login_username)
    EditText edt_login_username;
    @BindView(R.id.edt_login_password)
    EditText edt_login_password;
    private ProgressDialog dialog;
    private LoginActivity mActivity;

    @Override
    protected int getLayout() {
        return R.layout.fragment_login;
    }

    @Override
    protected void initView(LayoutInflater inflater) {
        mActivity = (LoginActivity) mContext;
        mPresenter = new LoginFragmentPresenter(this);
        dialog = new ProgressDialog(mContext);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setMessage("登陆中...");
    }

    @OnClick({R.id.bt_login_submit, R.id.bt_verification, R.id.tv_pwd_login})
    void clickEvent(View view) {
        String login_username = edt_login_username.getText().toString();
        switch (view.getId()) {
            case R.id.bt_login_submit:
                String login_password = edt_login_password.getText().toString();
                KL.d(LoginRegisterFragment.class, "login_username:" + login_username + ",login_password:" + login_password);
                mPresenter.bombUserLogin(login_username, login_password, 0);
                break;
            case R.id.bt_verification:
                KL.d(LoginRegisterFragment.class, "login_username:" + login_username);
                mPresenter.bombRequestSms(login_username);
                break;
            case R.id.tv_pwd_login:
                mActivity.jumpToLogin();
                break;
        }
    }

    @Override
    protected void lazyFetchData() {
        super.lazyFetchData();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void showProgressDialog() {
        dialog.show();
    }

    @Override
    public void hideProgressDialog() {
        dialog.dismiss();
    }

    @Override
    public void LoginSuccess() {

    }

    @Override
    public void loginFail() {

    }


    @Override
    public void showMessage(String text) {
        EventUtil.showToast(mContext, text);
    }

    @Override
    public void setPresenter(LoginFragmentContract.Presenter presenter) {
        mPresenter = Preconditions.checkNotNull(presenter);
    }

    @Override
    public void showError(String msg) {
        EventUtil.showToast(mContext, msg);
    }
}
